using UnityEngine;
using UnityEditor;
using System.Collections;
using DanielSig;
using DanielSig.UnityExtensions;

public class SpatialLogger : MonoBehaviour
{
	
	public SpatialLog[] Logs;
	private SmartList<SpatialLog> _logs;
	private GUIStyle _style;
	private int timeout = 0;
	
	void Awake()
	{
		_logs = new SmartList<SpatialLog>(Logs ?? new SpatialLog[1]);
		Logs = _logs.RawArray;
	}
	void OnGUI()
	{
		if(timeout > 5) return;
		timeout++;
		
		
		
		if(_style == null)
		{
			_style = new GUIStyle(GUI.skin.label);
			_style.alignment = TextAnchor.MiddleCenter;
		}
		foreach(SpatialLog log in _logs)
		{
			Vector3 center = Camera.main.WorldToScreenPoint(log.Position);
			float width = log.Message.Length * 10;
			float height = 25;
			Rect rect = new Rect(center.x - width / 2, Screen.height - height / 2 - center.y, width, height);
			GUI.Label(rect, log.Message, _style);
		}
	}
	public void Add(SpatialLog log)
	{
		_logs.Add(log);
	}
	void LateUpdate()
	{
		timeout = 0;
		_logs.Clear();
	}
}

